<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@page import="castleContent.Archer"%>
<%@page import="controler.CreateSoldierServlet"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>

<%@page import="castleContent.Barbarian"%>
<%@page import="castleContent.Archer"%>
<%@page import="castleContent.Wizzard"%>
<%@page import="castleContent.Castle"%>
<%@page import="castleContent.Barracks"%>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<script type="text/javascript" src="jquery-2.1.1.js"></script>

<style>
div {
	float: left;
	text-align: center;
	margin-left: 5%;
}

div.Castle {
	margin-top: 15%;
}
</style>

<script>
	function upgradeSoldierServletGetMethod(warriorUpradeType) {
		$.get(
				"http://localhost:8080/GameDevelopment/UpgradeServlet?warriorUpgradeType="
						+ warriorUpgradeType, function(data) {
					$("#Resources").html(data);
				});
	}
	function crateSoldierServletGetMethod(warriorType) {
		$.get(
				"http://localhost:8080/GameDevelopment/CreateSoldierServlet?warriorType="
						+ warriorType, function(data) {
					$("#Resources").html(data);
				});
	}

	//Create Barbarian
	function createBarbarian() {
		warriorType = "Barbarian";
		crateSoldierServletGetMethod(warriorType);
	}
	//Upgrade Barbarian ATT
	function upBarbarianAtt() {
		warriorUpgradeType = "BarbarianAtt";
		upgradeSoldierServletGetMethod(warriorUpgradeType);
	}
	//Upgrad Barbarian HP
	function upBarbarianHp() {
		warriorUpgradeType = "BarbarianHp";
		upgradeSoldierServletGetMethod(warriorUpgradeType)
	}
	//Create Archer
	function createArcher() {
		warriorType = "Archer";
		crateSoldierServletGetMethod(warriorType);
	}
	//Upgrade Archer ATT
	function upArcherAtt() {
		warriorUpgradeType = "ArcherAtt";
		upgradeSoldierServletGetMethod(warriorUpgradeType);
	}
	//Upgrade Archer HP
	function upArcherHp() {
		warriorUpgradeType = "ArcherHp";
		upgradeSoldierServletGetMethod(warriorUpgradeType);
	}
	//Create Wizard
	function createWizard() {
		warriorType = "Wizard";
		crateSoldierServletGetMethod(warriorType);
	}
	//Upgrade Wizard ATT
	function upWizardAtt() {
		warriorUpgradeType = "WizardAtt";
		upgradeSoldierServletGetMethod(warriorUpgradeType);
	}
	//Upgrade Wizard HP
	function upWizardHp() {
		warriorUpgradeType = "WizardHp";
		upgradeSoldierServletGetMethod(warriorUpgradeType);
	}
</script>
</head>
<body>
	<%
		Castle castle = (Castle) session.getAttribute("Castle");
		Barbarian barbarian = new Barbarian(castle.getBarracks()
				.getBarbarianADLevel(), castle.getBarracks()
				.getBarbarianHPLevel());
		Archer archer = new Archer(castle.getBarracks().getArcherADLevel(),
				castle.getBarracks().getArcherHPLevel());
		Wizzard wizard = new Wizzard(castle.getBarracks()
				.getWizzardADLevel(), castle.getBarracks()
				.getWizzardHPLevel());
	%>
	<h1 id="Resources">
		Food :
		<%=castle.getFoodFarm().getAvailableResource()%>
		Gold :
		<%=castle.getGoldMine().getAvailableResource()%>
		<br> Army : <%=castle.getBarracks().getPresentArmy()%>
		/
		<%=castle.getBarracks().getArmyCapacity()%>
		<br>
		Barbarians : <%= castle.getBarracks().getBarbarians() %>
		Archers : <%= castle.getBarracks().getArchers() %>
		Wizards : <%= castle.getBarracks().getWizzards() %>
	</h1>

	<div>
		<H2>Barbarian</H2>
		<h5>
			Strong mele warrior, fearless and brave.<br> hp: <%=barbarian.getHealthPoints()%><br>
				att: <%=barbarian.getAttackDamage()%><br> ad level : <%=barbarian.getAdLevel()%><br>
				hp level : <%=barbarian.getHpLevel()%><br> Cost : 150 food 
		</h5>
		<div>
			Cost : 500 gold Cost : 500 gold <br>
			<BUTTON onclick="upBarbarianAtt()">Upgrade Att</BUTTON>
			<BUTTON onclick="upBarbarianHp()">Upgrade HP</BUTTON>
		</div>
		<br>
		<BUTTON onclick="createBarbarian()">Create</BUTTON>
	</div>

	<div style="text-align: center">
		<H2>Archer</H2>
		<h5>
			Accurate ranger who never misses the target.<br> hp: <%=archer.getHealthPoints()%><br>
				att: <%=archer.getAttackDamage()%><br> ad level : <%=archer.getAdLevel()%><br>
				hp level : <%=archer.getHpLevel()%><br> Cost : 300 food 
		</h5>
		<div>
			Cost : 500 gold Cost : 500 gold <br>
			<BUTTON onclick="upArcherAtt()">Upgrade Att</BUTTON>
			<BUTTON onclick="upArcherHp()">Upgrade HP</BUTTON>
		</div>
		<br>
		<BUTTON onclick="createArcher()">Create</BUTTON>
	</div>

	<div style="text-align: center; width: 18%">
		<H2>Wizard</H2>
		<h5>
			Mighty sorcerer.<br> hp: <%=wizard.getHealthPoints()%><br>
				att: <%=wizard.getAttackDamage()%><br> ad level : <%=wizard.getAdLevel()%><br>
				hp level : <%=wizard.getHpLevel()%><br> Cost : 500 food 
		</h5>
		<div>
			Cost : 500 gold Cost : 500 gold <br>
			<BUTTON onclick="upWizardAtt()">Upgrade Att</BUTTON>
			<BUTTON onclick="upWizardHp()">Upgrade HP</BUTTON>
		</div>
		<br>
		<BUTTON onclick="createWizard()">Create</BUTTON>
	</div>
	<div class="Castle">
		<a href="HumanCastle.jsp"><img src="Arrow.png" height="15%"
			width="20%" />
	</div>
</body>
</html>